using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace Lync.Widget.Library.Configuration
{
    public class LanguageElement : ConfigurationElement, ILanguagePack
    {
        [ConfigurationProperty("id", IsRequired = true, IsKey = true)]
        public string Language
        {
            get
            {
                return this["id"] as string;
            }
            set
            {
                this["id"] = value;
            }
        }

        [ConfigurationProperty("isdefault", IsRequired = false, DefaultValue = false)]
        public bool IsDefault
        {
            get
            {
                var boolString = this["isdefault"].ToString();
                
                bool result;
                bool.TryParse(boolString, out result);
                return result;
            }
            set
            {
                this["isdefault"] = value;
            }
        }

        public IList<ILanguageResource> Resources
        {
            get
            {
                return LanguageResources != null ? LanguageResources.Cast<ILanguageResource>().ToList() : null;
            }
        }

        [ConfigurationProperty("Resources")]
        private LanguageResourceElementCollection LanguageResources
        {
            get
            {                
                var temp = this["Resources"] as LanguageResourceElementCollection;
                return temp;
            }
        }
    }
}